home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / funcs.c < prev    next >
C/C++ Source or Header  |  1993-05-21  |  3KB  |  141 lines

  1. /*    Copyright (C) 1993 Free Software Foundation, Inc.
  2.  
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7.  
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12.  
  13. You should have received a copy of the GNU General Public License
  14. along with this software; see the file COPYING.  If not, write to
  15. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17.  
  18.  
  19. /* 
  20.  * This file contains descriptions of all the interactive functions 
  21.  * built into oleo. 
  22.  */
  23.  
  24. #include "global.h"
  25. #include "cmd.h"
  26. #include "key.h"
  27. #include "io-term.h"
  28. #include "basic.h"
  29. #include "format.h"
  30. #include "print.h"
  31. #include "font.h"
  32. #include "io-x11.h"
  33. #include "io-edit.h"
  34. #include "regions.h"
  35. #include "help.h"
  36. #include "window.h"
  37. #include "font.h"
  38. #include "graph.h"
  39. #include "lists.h"
  40.  
  41.  
  42. /* This include builds the function table, doc strings, and FUNC_ARGS strings.
  43.  */
  44. #include "defuns.h"
  45.  
  46.  
  47. /* Returns 0 if the function is found.
  48.  * Also returns (through parameters) the vector and cmd_func.
  49.  * The output parameters can be NULL.
  50.  */
  51.  
  52. #ifdef __STDC__
  53. int
  54. find_function (int * vec_out, struct cmd_func ** cmd_out, char * name, int len)
  55. #else
  56. int
  57. find_function (vec_out, cmd_out, name, len)
  58.      int * vec_out;
  59.      struct cmd_func ** cmd_out;
  60.      char * name;
  61.      int len;
  62. #endif
  63. {
  64.   int vector;
  65.   struct cmd_func * cmd;
  66.   for (vector = 0; vector < num_funcs; vector++)
  67.     for (cmd = &the_funcs[vector][0]; cmd->func_name; cmd++)
  68.       if (!(strincmp (name, cmd->func_name, len) || cmd->func_name[len]))
  69.     {
  70.       if (vec_out)
  71.         *vec_out = vector;
  72.       if (cmd_out)
  73.         *cmd_out = cmd;
  74.       return 0;
  75.     }
  76.   return 1;
  77. }  
  78.  
  79.  
  80.  
  81.  
  82. static struct cmd_func * named_macro_strings = 0;
  83. static int num_named_macro_strings = 0;
  84. static int named_macro_vec;
  85.  
  86. #ifdef __STDC__
  87. void
  88. init_named_macro_strings (void)
  89. #else
  90. void
  91. init_named_macro_strings ()
  92. #endif
  93. {
  94.   named_macro_strings =
  95.     (struct cmd_func *) ck_malloc (sizeof (struct cmd_func));
  96.   bzero (named_macro_strings, sizeof (struct cmd_func));
  97.   named_macro_vec = add_usr_cmds (named_macro_strings);
  98. }
  99.  
  100.  
  101. #ifdef __STDC__
  102. void 
  103. name_macro_string (char * name, char * str)
  104. #else
  105. void 
  106. name_macro_string (name, str)
  107.      char * name;
  108.      char * str;
  109. #endif
  110. {
  111.   int i = num_named_macro_strings;
  112.   ++num_named_macro_strings;
  113.   named_macro_strings =
  114.     ((struct cmd_func *)
  115.      ck_realloc (named_macro_strings,
  116.          ((1 + num_named_macro_strings) * sizeof (struct cmd_func))));
  117.   the_funcs [named_macro_vec] = named_macro_strings;
  118.   bzero (named_macro_strings + num_named_macro_strings,
  119.      sizeof (struct cmd_func));
  120.   {
  121.     struct cmd_func * cf = &named_macro_strings [i];
  122.     cf->func_name = ck_savestr (name);
  123.     cf->func_func = run_string_as_macro;
  124.     cf->init_code = 0;
  125.     {
  126.       struct info_buffer * ib = find_or_make_info (name);
  127.       clear_info (ib);
  128.       print_info (ib, "Equivalent to %s.", str);
  129.       cf->func_doc = ib->text;
  130.     }
  131.     {
  132.       int i = 0;
  133.       cf->func_args = (char **)ck_malloc (3 * sizeof (char *));
  134.       cf->func_args [i++] = mk_sprintf ("=%s", str);
  135.       cf->func_args [i++] = "p";
  136.       cf->func_args [i++] = 0;
  137.     }
  138.   }
  139. }
  140.  
  141.